﻿using System.Collections.Generic;
using ZilLion.Core.DatabaseWrapper.SqlServer;
using ZilLion.Task.Domain.Entity;

namespace ZilLion.Task.Domain.Respository
{
    public class TaskCommandRespository : SqlServerRespository<TaskConmmandEntity>
    {
        public TaskCommandRespository()
        {
            Context = new TaskRunnerContext();
        }

        public IEnumerable<TaskConmmandEntity> GetAllTaskConmmandEntities(string nodeid = null)
        {
            if (nodeid.IsNotNullOrEmpty())
                return GetList("select * from [task_command] where nodeid=@nodeid", new {nodeid});
            return GetList("select * from [task_command] ");
        }

        public IEnumerable<TaskConmmandEntity> GetUnHandleTaskConmmandEntities(string nodeid = null)
        {
            if (nodeid.IsNotNullOrEmpty())
                return GetList("select * from [task_command] where nodeid=@nodeid and commandstate=0 ", new { nodeid });
            return GetList("select * from [task_command] where commandstate=0");
        }


        public void SaveTaskConmmandEntity(TaskConmmandEntity command)
        {
            if (command.CommandId == 0)
            {
                Add(command);
            }
            else
            {
                Modify(command);
            }
        }
    }
}